package com.wuxiaolong.androidmvpsample.mvp.main;

import com.wuxiaolong.androidmvpsample.mvp.other.BasePresenter;
import com.wuxiaolong.androidmvpsample.retrofit.ApiCallback;

import java.util.List;
import java.util.Map;

import okhttp3.MultipartBody;
import okhttp3.RequestBody;

/**
 * Created by WuXiaolong on 2015/9/23.
 * github:https://github.com/WuXiaolong/
 * 微信公众号：吴小龙同学
 * 个人博客：http://wuxiaolong.me/
 */
public class MainPresenter extends BasePresenter<MainView> {

    public MainPresenter(MainView view) {
        attachView(view);
    }

    public void loadDataByRetrofitRxjava(String cityId, Map<String, String> map) {
        mvpView.showLoading();
        addSubscription(apiStores.loadDataByRetrofitRxjava(cityId, map),
                new ApiCallback<MainModel>() {
                    @Override
                    public void onSuccess(MainModel model) {
                        mvpView.getDataSuccess(model);
                    }

                    @Override
                    public void onFailure(String msg) {
                        mvpView.getDataFail(msg);
                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }

    public void postUserInfo(Map<String, String> map) {
        mvpView.showLoading();
        addSubscription(apiStores.postMapUserInfoRx(map), new ApiCallback<MainModel>() {
            @Override
            public void onSuccess(MainModel model) {
//                mvpView.getDataSuccess(model);
                mvpView.hideLoading();
            }

            @Override
            public void onFailure(String msg) {
                mvpView.getDataFail(msg);
                mvpView.hideLoading();
            }

            @Override
            public void onFinish() {
                mvpView.hideLoading();
            }
        });
    }

    public void postFileUser(MultipartBody.Part file, Map<String, String> param) {
        mvpView.showLoading();
        addSubscription(apiStores.postFileUser(file, param), new ApiCallback<MainModel>() {
            @Override
            public void onSuccess(MainModel model) {
//                mvpView.getDataSuccess(model);
            }

            @Override
            public void onFailure(String msg) {
                mvpView.getDataFail(msg);
            }

            @Override
            public void onFinish() {
                mvpView.hideLoading();
            }
        });
    }

    public void postFilesUser(Map<String, List<RequestBody>> params, Map<String, String> map) {
        mvpView.showLoading();
        addSubscription(apiStores.postFilesUser(params, map), new ApiCallback<MainModel>() {
            @Override
            public void onSuccess(MainModel model) {
//                mvpView.getDataSuccess(model);
            }

            @Override
            public void onFailure(String msg) {
                mvpView.getDataFail(msg);
            }

            @Override
            public void onFinish() {
                mvpView.hideLoading();
            }
        });
    }

}
